//
//  MYGCloudDiskEditBriefView.swift
//  MYDoctor
//
//  Created by Denny on 2024/3/15.
//

import UIKit

class MYGCloudDiskEditBriefView: UIView {
    @IBOutlet weak var limitLB: UILabel!
    
    @IBOutlet weak var sureBtn: UIButton!
    @IBOutlet weak var contentTexView: UITextView!
    var tapSureCallBack:((String)->Void)?
    override  func awakeFromNib() {
        super.awakeFromNib()
        contentTexView.placeholderText = "填写共享文件夹简介"
        contentTexView.delegate = self
        sureBtn.addCAGradientLayerColor(colors: [UIColor.init(hexString: "#97B3FF").cgColor,
                                                 UIColor.init(hexString: "#4975EC").cgColor],
                                        startPoint: CGPoint(x: 0, y: 0), endPoint: CGPoint.init(x: 1, y: 0))
        sureBtn.layer.cornerRadius = 20
        sureBtn.layer.masksToBounds = true
        
    }
    var content:String = "" {
        didSet {
            self.contentTexView.text = content
            limitLB.text = "\(contentTexView.text.count)/50"

        }
    }
    @IBAction func tapSure(_ sender: UIButton) {
        if let c = tapSureCallBack{
            if self.contentTexView.text.count > 0 {
                c(self.contentTexView.text)
            }
        }
    }
}

extension MYGCloudDiskEditBriefView: UITextViewDelegate {
    func textViewDidChange(_ textView: UITextView) {
        let count = textView.text.count
        if count > 50 {
            let endIndex = textView.text.index(textView.text.startIndex, offsetBy: 50)
            textView.text = String(textView.text.prefix(upTo: endIndex))
            
        }
        limitLB.text = "\(textView.text.count)/50"
    }
}
